package hydrap2p.gui.commands;

import java.util.Stack;

public class CommandInvoker {
	private Stack<Command> cmdStack = new Stack<Command>();
	private static CommandInvoker instance;
	
	private CommandInvoker(){};
	
	public static synchronized CommandInvoker getInstance(){
		if(instance == null){
			synchronized (CommandInvoker.class){
				if(instance == null){
					instance = new CommandInvoker();
				}
			}
		}
		return instance;
	}
	
	public void invokeCommand(Command cmd){
		cmd.execute();
		cmdStack.push(cmd);
	}
	
	public void undo(){
		if(cmdStack.size() >= 1){
			cmdStack.pop().unexecute();
		}
	}
}
